//导入网络模块
import http from '@ohos.net.http';
import api from './index'

//封装GET请求
const get = (url:string,data={})=>{
  let str = '';
  if(data){
    for(let key in data){
      str+=key+'='+data[key]+'&'
    }
    str=str.slice(0,str.length-1)
    console.log(str)
  }
  let httpRequest = http.createHttp();
  return httpRequest.request(
    str?url+'?'+str: url,
    {
      method: http.RequestMethod.GET,// 请求方式
      connectTimeout: 60000,
      readTimeout: 60000,
      header: {
        'Content-Type': 'application/json' // 请求头信息
      }
    })
}

const post = (url:string,data={})=>{
  let httpRequest = http.createHttp();
  return httpRequest.request(
    url,
    {
      method: http.RequestMethod.POST,// 请求方式
      extraData: data,// 传递参数给后台
      connectTimeout: 60000,
      readTimeout: 60000,
      header: {
        'Content-Type': 'application/json' // 请求头信息
      }
    })
}

// 接口一：
// 分类频道
export  const getClass = (data={})=>{
  return get(`${api.host}/mergedCategroy.json`,data)
}
// 子分类
export  const getCate =(data={})=>{
  return get(`${api.host}/store/info.json?type=female&bar=cat&uuid=d6f496cf3b45479795fe087dbb5ea90a`,data)
}
// 分类书籍
export  const getClassBook = (data={})=>{
  return get(`${api.host}/category/original/data.json?id=8&gender=female&sort=2&pay=0&state=0&page=1`,data)
}
// 书籍详情
export  const getDetail = (data={})=>{
  return get(`${api.host}/book/getsub.json`,data)
}
// 书籍章节
export  const getCatalog =(data={})=>{
  return get(`${api.host}/book/catalog.json`,data)
}
// 书籍评论
export  const getComment =(data={})=>{
  return get(`${api.host}/comment/getComments.json`,data)
}
// 书架图书
export const getBookshelf = (data={})=>{
  return get(`${api.host}/shelf/detail.json`,data)
}
// 书架图书
export const getBookStore = (data={})=>{
  return get(`${api.host}/store/show.json`,data)
}











